package com.sunnypower.rushfitapp.CourseHistorypart;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.sunnypower.rushfitapp.R;
import com.sunnypower.rushfitapp.db.VHistory;
import com.sunnypower.rushfitapp.util.ParseStringToOther;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

public class VHistoryAdapter extends ArrayAdapter<VHistory> {

    public VHistoryAdapter(@NonNull Context context, int resource, @NonNull List<VHistory> objects) {
        super(context, resource, objects);
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        VHistory vHistory = getItem(position);
        View view = LayoutInflater.from(getContext()).inflate(R.layout.activity_v_history_part, parent, false);
        TextView history_course_name = view.findViewById(R.id.history_course_name);
        TextView history_course_rate = view.findViewById(R.id.history_course_rate);
        TextView history_course_time = view.findViewById(R.id.history_course_time);

        history_course_name.setText(vHistory.getName());
        if (vHistory.getRate() != null) {
            history_course_rate.setText("       " + vHistory.getRate().toString().substring(0, 1));
        } else {
            history_course_rate.setText("   请评分");
        }
        history_course_time.setText(vHistory.getTime().toString());

        return view;
    }
}
